package leetcode;

public class RemoveNthNode {

	 public ListNode removeNthFromEnd(ListNode head, int n) {
	 
		 int count=0;
		 ListNode remove=head;		 
		 while(null!=remove){
			 remove=remove.next;
			 count++;
		 }
		 if(count<=n)return head.next;
		 
		 remove=head;
		 for(int i=1;i<count-n;i++)
			 remove=remove.next;

		 if(null!=remove.next){
			 remove.next=remove.next.next;
		 }
			 
	     return head;		 
	 }
}
